package com.zhanggm.springboot.demo.config;

import com.zhanggm.springboot.demo.common.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 全局异常处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 异常处理的方法
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public @ResponseBody JsonResult exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception e){
        return JsonResult.error(10000,e.getMessage());
    }

   /* @ExceptionHandler(value = Exception.class)
    public @ResponseBody JsonResult exceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception e){
        return JsonResult.error(10000,e.getMessage());
    }*/
}
